<template>
  <div>
    <van-field v-model="currentValue.name" :label="title" input-align="right" placeholder="请选择" readonly clickable is-link @click="showPicker" />
    <popup-list ref="popupList" :search="search" @confirm="getValue" />
  </div>
</template>

<script>
import popupList from './popupList';
export default {
  props:{
    title: {
      type: String
    },
    list: {
      type: Array,
      default: () => [],
    },
    value:{
      type: String | Number,
      default: null,
    },
    search:{
      type: Boolean,
      default: () => false,
    }
  },
  data(){
    return{
      
    }
  },
  components:{
    popupList,
  },
  computed:{
    currentValue(){
      let obj = {};
      if(this.value && this.list.length > 0){
        let arr = this.list.filter(item => item.id == this.value);
        obj = arr[0];
      }
      return obj;
    },
    lists(){
      return this.list;
    }
  },
  methods:{
    showPicker(){
      this.$refs.popupList.init(this.currentValue,this.lists);
    },
    getValue(data){
      this.$emit('update:value', data.id);
      this.$emit('confirm', data);
    }
  }
}
</script>

<style>

</style>